﻿using System.ComponentModel;
using System.Web.UI;

namespace KamLib
{
    public static class SystemWeb
    {
        public static T Parent<T>(this Control self)
            where T : Control
        {
            var p = self.Parent;
            while (p != null && !(p is T))
            {
                p = p.Parent;
            }
            return p as T;
        }

        public static T IParent<T>(this Control self)
            where T : IComponent
        {
            var p = self.Parent;
            while (p != null)
            {
                if (p is T) return (T)(IComponent)p;
                p = p.Parent;
            }
            return default(T);
        }

    }
}
